package com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.menu.impl;

import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.entity.MenuItem;
import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.iterator.impl.DinerMenuIterator;
import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.menu.Menu;

import java.util.Iterator;

/**
 * 晚餐菜单
 * @author 、
 */
public class DinerMenu implements Menu {

    private static final int MAX_TIMES = 6;
    private int numberOfItems = 0;
    private MenuItem[] menuItems;

    public DinerMenu() {
        menuItems = new MenuItem[MAX_TIMES];

        addItem("Vegetarian BLT",
                "(Fakin') Bacon with lettuce & tomato on whole wheat",
                true,
                2.99);

        addItem("BLT",
                "Bacon with lettuce & tomato on whole wheat",
                false,
                2.99);

        addItem("Soup of the day",
                "Soup of the day, with a side of potato salad",
                false,
                3.29);

        addItem("Hotdog",
                "A hot dog, with saurkraut, relish, onions, topped with cheese",
                false,
                3.05);

    }

    public void addItem(String name, String description,
                        boolean vegetarian, double price) {
        MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
        if (numberOfItems >= MAX_TIMES) {
            System.err.println("Sorry, menu is full!! Can't add item to menu");
        } else {
            menuItems[numberOfItems] = menuItem;
            numberOfItems = numberOfItems + 1;
        }
    }

    @Override
    public Iterator createIterator() {
        return new DinerMenuIterator(menuItems);
    }

}
